[bits 32]
global asm_hello_world
global asm_lidt
global asm_unhandled_interrupt
global asm_halt

asm_hello_world:
    push eax
    push ebx
    push ecx
    push esi
    ;输出标签
    mov ecx,string_end - string
    mov ebx,(80*10+10)*2 ;(10,10)
    mov esi,string
    mov ah,0x5b		;背景红 字体青色
    output_string:
        mov al,[esi]
        mov word[gs:ebx],ax
        add ebx,2
        inc esi
        loop output_string
    pop esi
    pop ecx
    pop ebx
    pop eax
    ret
;void asm_lidt(uint32 start,uint16 limit)IDT的基地址和表界限
asm_lidt:
    push ebp
    mov ebp,esp
    push eax
    
    mov eax,[ebp+4*3]		;注意栈有哪些元素，此处应该是3个双字dw
    mov [ASM_IDTR],ax
    mov eax,[ebp+4*2]
    mov [ASM_IDTR+2],eax
    lidt [ASM_IDTR]
    
    pop eax
    pop ebp
    ret
asm_unhandled_interrupt:
    cli
    mov esi,ASM_UNHANDLED_INTERRUPT_INFO
    xor ebx,ebx
    mov ah,0x04
    .output_information:
        cmp byte[esi],0
        je .end
        mov al,byte[esi]
        mov word[gs:bx],ax
        inc esi
        add ebx,2
        jmp .output_information
    .end:
    jmp $
asm_halt:
    jmp $

.data:
ASM_IDTR dw 0
	 dd 0
ASM_UNHANDLED_INTERRUPT_INFO db "Unhandled interrupt happened,halt..."
			     db 0     
string db "22336271 ysj,dear,I'm your operating system!Thank you:)"
string_end:
